#pragma once
#include <SFML/Graphics/Text.hpp>
#include <nice2d/widgets/basicbutton.h>

class ButtonStyle : public BasicButtonStyle
{
    DECLARE_OBJECT(ButtonStyle)
public:
    ButtonStyle();
    virtual ~ButtonStyle();
public:
    virtual PTree serialize()override;
    virtual void deserialize(const PTree &node)override;
    virtual void sync()override;
public:
    std::string fontFile = "./../data/font/arial.ttf";
    float characterSize = 15.0f;
    HMode hMode = HMode_Center;
    VMode vMode = VMode_Center;

    sf::Text::Style style = sf::Text::Style::Regular;
    sf::Color textColor = sf::Color::White;
};

class Button : public BasicButton
{
    DECLARE_OBJECT(Button)
public:
    Button(const sf::Vector2f &size = sf::Vector2f(150, 36));
    virtual ~Button();
public:
    void setText(const sf::String &text);
    sf::String getText()const;
protected:
    void onPositionChanged() override;
    void onButtonStateChanged() override;
    void recalcTextPosition(float offsetx, float offsety);
    void onDrawControl(sf::RenderTarget &target, sf::RenderStates states) const override;

    virtual void onStyleChanged()override;
private:
    std::unique_ptr<class ButtonData> data;
};
